package com.lanou.musicproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.musicproject.R;
import com.lanou.musicproject.bean.MoreNewSong;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 王世美 on 15/10/29.
 * 最新歌曲页面
 */
public class MoreNewSongAdapter extends BaseAdapter {
    private List<MoreNewSong.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity> data;
    private Context context;

    public MoreNewSongAdapter(Context c, List<MoreNewSong.PlazeAlbumListEntity.
            RMEntity.AlbumListEntity.ListEntity> data) {
        this.data = data;
        context = c;
    }

    @Override
    public int getCount() {
        if (data != null && data.size() > 0)
            return data.size();
        else
            return 0;
    }

    @Override
    public MoreNewSong.PlazeAlbumListEntity.RMEntity.
            AlbumListEntity.ListEntity getItem(int position) {
        if (data != null && data.size() > 0)
            return data.get(position);
        else
            return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position,
                        View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.more_song_gridview_item,null);
            holder = new ViewHolder();
            holder.backgroundIV = (ImageView) convertView.findViewById(R.id.backgroundIV);
            holder.songTitleTV = (TextView) convertView.findViewById(R.id.songTitleTV);
            holder.songAuthorTV = (TextView) convertView.findViewById(R.id.songAuthorTV);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MoreNewSong.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity list = getItem(position);
        if (list != null) {
            Picasso.with(context).load(list.getPic_radio()).into(holder.backgroundIV);
            holder.songTitleTV.setText(list.getTitle());
            holder.songAuthorTV.setText(list.getAuthor());
        }
        return convertView;
    }

    private class ViewHolder{
        public ImageView backgroundIV;
        public TextView songTitleTV;
        public TextView songAuthorTV;
    }
}

